import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    debugShowCheckedModeBanner: false,
    home: HomePage(),
  ));
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  void openDialog(BuildContext context) async {
    var result = await showDialog(
        barrierDismissible: false,
        context: context,
        builder: (context) {
          return AlertDialog(
            title: const Text("提示信息"),
            content: const Text("你确定删除吗？"),
            actions: [
              TextButton(
                onPressed: () {
                  print("取消");
                  Navigator.pop(context, false);
                },
                child: const Text("取消"),
              ),
              TextButton(
                onPressed: () {
                  print("确定");
                  Navigator.pop(context, true);
                },
                child: const Text("确定"),
              ),
            ],
          );
        });
    if (result) {
      print("点击了确认");
    } else {
      print("点击了取消");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Alert"),
      ),
      body: Center(
        child: ElevatedButton(
            onPressed: () {
              openDialog(context);
            },
            child: const Text("打开AlertDialog传值")),
      ),
    );
  }
}
